package com.wangzhenyu.learn.test.android_.activity

import android.os.Bundle
import com.wangzhenyu.learn.databinding.ActivitySecondTestBinding
import com.wangzhenyu.common.base.BaseVBActivity
import com.wangzhenyu.learn.test.android_.fragment_.DocumentFragment
import com.wangzhenyu.learn.test.android_.adapter_.FragmentForClick
import com.wangzhenyu.learn.test.android_.fragmentViewModel.FirstFragment
import com.wangzhenyu.learn.test.android_.fragmentViewModel.RoomTestFragment
import com.wangzhenyu.learn.test.android_.fragmentViewModel.TestListFragment

class SecondTestActivity : FragmentForClick, BaseVBActivity<ActivitySecondTestBinding>() {

    override fun getViewBinding() = ActivitySecondTestBinding.inflate(layoutInflater)

    private val list = arrayListOf("Room测试", "对话框", "文件相关")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //添加列表Fragment
        val bundle = Bundle().apply {
            putStringArrayList("list", list)
        }
        val transaction = supportFragmentManager.beginTransaction()
        transaction.add(binding.fragmentContainerView.id, TestListFragment::class.java, bundle)
            .setReorderingAllowed(true)
            .commit()

    }

    override fun onRecyclerViewClick(position: Int) {
        when (position) {
            0 -> {
                val bundle = Bundle().apply {
                    putString("title", list[position])
                }
                supportFragmentManager.beginTransaction()
                    .replace(binding.fragmentContainerView.id, RoomTestFragment::class.java, bundle)
                    .addToBackStack(list[position])
                    .commit()
            }
            1 -> {
                val bundle = Bundle().apply {
                    putString("title", list[position])
                }
                supportFragmentManager.beginTransaction()
                    .replace(binding.fragmentContainerView.id, FirstFragment::class.java, bundle)
                    .addToBackStack(list[position])
                    .commit()
            }
            //文件相关
            2 -> {
                val bundle = Bundle().apply {
                    putString("title", list[position])
                }
                supportFragmentManager.beginTransaction()
                    .replace(binding.fragmentContainerView.id, DocumentFragment::class.java, bundle)
                    .addToBackStack(list[position])
                    .commit()
            }
        }
    }

}